package com.example.hdwx.myapplication.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.example.hdwx.myapplication.R;
import com.example.hdwx.myapplication.eneity.daydaycook_eneitys.Daydaycook_eneity;
import com.example.hdwx.myapplication.eneity.daydaycook_eneitys.Daydaycook_everyday_eneity;
import com.example.hdwx.myapplication.eneity.daydaycook_eneitys.Daydaycook_hot_eneity;
import com.example.hdwx.myapplication.eneity.daydaycook_eneitys.Daydaycook_raiders_eneity;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.ColorPointHintView;

import java.util.List;

/**
 * Created by hdwx on 2017/2/13.
 */

public class Daydaycook_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    final String TAG = "Daydaycook_adapter";
    List<Daydaycook_eneity> list;
    List<Daydaycook_everyday_eneity> list1;
    List<Daydaycook_hot_eneity> list2;
    List<Daydaycook_raiders_eneity> list3;
    Context context;

    //构造器
    public Daydaycook_adapter(List<Daydaycook_eneity> list, List<Daydaycook_everyday_eneity> list1, List<Daydaycook_hot_eneity> list2, List<Daydaycook_raiders_eneity> list3, Context context) {
        this.list = list;
        this.list1 = list1;
        this.list2 = list2;
        this.list3 = list3;
        this.context = context;
    }
//判断视图和获取视图的种类
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);
        if (viewType == R.layout.daydaycook_ksrk) {
                return new twoViewHolder(view);
        } else if (viewType == R.layout.daydaycook_item) {
            return new threeViewHolder(view);
        } else if (viewType == R.layout.daydaycook_item1) {
            return new fourViewHolder(view);
        } else if (viewType == R.layout.daydaycook_item2) {
            return new fiveViewHolder(view);
        } else if (viewType == R.layout.commoon_rollpager_view) {
            return new oneViewHolder(view);
        }
        return null;
    }
//获取视图中的控件
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof oneViewHolder) {
            //图片轮播切换时间
            ((oneViewHolder) holder).rollPagerView.setPlayDelay(1000);
            // 设置图片轮播适配器
            ((oneViewHolder) holder).rollPagerView.setAdapter(new RollPagerAdapter(list, context));
            //设置图片轮播小圆点
           ((oneViewHolder) holder).rollPagerView.setHintView(new ColorPointHintView(context, Color.YELLOW, Color.WHITE));
        }else if(holder instanceof twoViewHolder){
        }
        else if (holder instanceof threeViewHolder) {
            ((threeViewHolder) holder).recyclerView.setAdapter(new Daydaycook_item_adapter(context, list1));
            ((threeViewHolder) holder).recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        } else if (holder instanceof fourViewHolder) {
            ((fourViewHolder) holder).recyclerView1.setAdapter(new Daydaycook_item_hot_adapter(context, list2));
            ((fourViewHolder) holder).recyclerView1.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        } else if (holder instanceof fiveViewHolder) {
            ((fiveViewHolder) holder).recyclerView2.setAdapter(new Daydaycook_item2_adapter(list3, context));
            ((fiveViewHolder) holder).recyclerView2.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        }
    }

//根据顺序判断视图类型
    public int getItemViewType(int position) {
        if (position == 0) {
            return R.layout.commoon_rollpager_view;
        }
        if (position == 1) {
            return R.layout.daydaycook_ksrk;
        }
        if (position == 2) {
            return R.layout.daydaycook_item;
        }
        if (position == 3) {
            return R.layout.daydaycook_item1;
        }
        if (position == 4) {
            return R.layout.daydaycook_item2;
        }
        return R.layout.daydaycook_ksrk;

    }
//
    @Override
    public int getItemCount() {
        return 5;
    }

    //图片轮播viewholder；
    class oneViewHolder extends RecyclerView.ViewHolder {
        RollPagerView rollPagerView;

        public oneViewHolder(View itemView) {
            super(itemView);
            rollPagerView = (RollPagerView) itemView.findViewById(R.id.common_RollPageView);
        }
    }
    class  twoViewHolder extends RecyclerView.ViewHolder {

        public twoViewHolder(View itemView) {
            super(itemView);
        }
    }

    class threeViewHolder extends RecyclerView.ViewHolder {
        TextView tx;

        RecyclerView recyclerView;

        public threeViewHolder(View itemView) {
            super(itemView);
            Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/碳化硅大黑体.ttf");
            tx = (TextView) itemView.findViewById(R.id.heiti0);
            tx.setTypeface(face);
            recyclerView = (RecyclerView) itemView.findViewById(R.id.daydaycook_item_recycle);
        }
    }

    class fourViewHolder extends RecyclerView.ViewHolder {
        TextView tx;
        RecyclerView recyclerView1;

        public fourViewHolder(View itemView) {
            super(itemView);
            Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/碳化硅大黑体.ttf");
            tx = (TextView) itemView.findViewById(R.id.heiti1);
            tx.setTypeface(face);
            recyclerView1 = (RecyclerView) itemView.findViewById(R.id.daydaycook_item1_recycle);
        }
    }

    class fiveViewHolder extends RecyclerView.ViewHolder {
        TextView tx;
        RecyclerView recyclerView2;

        public fiveViewHolder(View itemView) {
            super(itemView);
            Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/碳化硅大黑体.ttf");
            tx = (TextView) itemView.findViewById(R.id.heiti2);
            tx.setTypeface(face);
            recyclerView2 = (RecyclerView) itemView.findViewById(R.id.daydaycook_item2_recycle);
        }
    }


}


